package com.spic.business.plan.book.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.spic.business.plan.book.domain.PlanStandingBookFile;
import com.spic.business.plan.book.mapper.PlanStandingBookFileMapper;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 应急预案附件Controller
 *
 * @author spic
 * @date 2021-11-01
 */
@RestController
@RequestMapping("/plan/book_file")
public class PlanStandingBookFileController extends BaseController
{
    @Autowired
    private PlanStandingBookFileMapper fileMapper;

    /**
     * 查询应急预案附件列表
     */
//    @PreAuthorize(hasPermi = "business:planStandingbookFile:list")
    @GetMapping("/list")
    public TableDataInfo list(PlanStandingBookFile bookFile)
    {
        startPage();
        List<PlanStandingBookFile> list = fileMapper.selectList(
                new LambdaQueryWrapper<PlanStandingBookFile>()
                    .eq(PlanStandingBookFile::getPlanStandingBookId, bookFile.getPlanStandingBookId())
        );
        return getDataTable(list);
    }


    /**
     * 新增应急预案附件
     */
//    @PreAuthorize(hasPermi = "business:planStandingbookFile:add")
    @Log(title = "应急预案附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PlanStandingBookFile planStandingBookFile)
    {
        return toAjax(fileMapper.insert(planStandingBookFile));
    }

    /**
     * 修改应急预案附件
     */
//    @PreAuthorize(hasPermi = "business:planStandingbookFile:edit")
    @Log(title = "应急预案附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PlanStandingBookFile planStandingBookFile)
    {
        return toAjax(fileMapper.updateById(planStandingBookFile));
    }

    /**
     * 删除应急预案附件
     */
//    @PreAuthorize(hasPermi = "business:planStandingbookFile:remove")
    @Log(title = "应急预案附件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable String id)
    {
        return toAjax(fileMapper.deleteById(id));
    }
}
